//
//  NoticeCell.m
//  Notice
//
//  Created by CPX on 2018/7/10.
//  Copyright © 2018年 CPX. All rights reserved.
//

#import "NoticeCell.h"

/**
 通知Cell
 */
@interface NoticeCell()

@property (nonatomic,strong) UIImageView *bgView;
@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UIView *dot;
@property (nonatomic,strong) UILabel *contentLabel;
@property (nonatomic,strong) UILabel *dateLabel;
@property (nonatomic, strong) UIImageView *avatarIV;

@end

@implementation NoticeCell

- (void)setNotice:(NoticeModel *)notice{
    _notice = notice;
    self.bgView.hidden = NO;
   
    self.dot.hidden = notice.status == 1;
    self.contentLabel.text = notice.body;
    self.dateLabel.text = notice.createDateFormatStr;
    [self.avatarIV sd_setImageWithURL:[NSURL URLWithString:notice.avatar] placeholderImage:[UIImage imageNamed:@"no_photo"]];
    if ([notice.event_type isEqualToString:@"system_notify"]) {
        self.titleLabel.text = @"iMuslim";
        self.titleLabel.font = [UIFont boldSystemFontOfSize:13];
        self.titleLabel.textColor = UIColorHex(#00732F);
        self.avatarIV.image = [UIImage imageNamed:@"icon90"];
    }
    else if([notice.event_type isEqualToString:@"comment"]){
        self.titleLabel.font = [UIFont systemFontOfSize:13];
         self.titleLabel.text = notice.pusher_name;
        self.titleLabel.textColor = UIColorHex(#001208);
    }
}

#pragma mark - lazy load

- (UIImageView*)bgView{
    if (!_bgView) {
        _bgView = [UIImageView new];
        _bgView.backgroundColor = [UIColor whiteColor];
        _bgView.layer.cornerRadius = 5;
        _bgView.layer.masksToBounds = YES;
        _bgView.userInteractionEnabled = YES;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
//        UIImage *image = [[UIImage imageNamed:@"shadow_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(4, 5, 8, 8) resizingMode:UIImageResizingModeStretch];
        //        _bgView.backgroundColor = [UIColor whiteColor];
//        _bgView.image = image;
        [self.contentView addSubview:_bgView];
        self.contentView.backgroundColor = UIColorHex(#f4f4f4);
        [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(12);
            make.trailing.mas_equalTo(-12);
            make.top.mas_equalTo(16);
            make.bottom.mas_equalTo(0);
        }];
    }
    return _bgView;
}

- (UILabel*)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:13];
        _titleLabel.textColor = UIColorHex(#001208);
        _titleLabel.numberOfLines = 0;
        [self.bgView addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.avatarIV).offset(2);
            make.leading.mas_equalTo(self.avatarIV.mas_trailing).offset(8);
            make.trailing.mas_equalTo(self.dot.mas_leading).offset(-10);
            make.height.mas_greaterThanOrEqualTo(10);
        }];
    }
    return _titleLabel;
}

- (UIView*)dot{
    if (!_dot) {
        _dot = [[UIView alloc] init];
        _dot.backgroundColor = UIColorHex(#FC3F1F);
        _dot.layer.cornerRadius = 2.5;
        _dot.layer.masksToBounds = YES;
        [self.bgView addSubview:_dot];
        [_dot mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(5, 5));
            make.trailing.mas_equalTo(-10);
            make.top.mas_equalTo(6);
        }];
    }
    return _dot;
}

- (UILabel*)contentLabel{
    if (!_contentLabel) {
        _contentLabel = [UILabel new];
        _contentLabel.font = [UIFont systemFontOfSize:15];
        _contentLabel.textColor = UIColorHex(#292929);
        _contentLabel.numberOfLines = 2;
        [self.bgView addSubview:_contentLabel];
        [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.avatarIV.mas_bottom).offset(12);
            make.leading.mas_equalTo(self.bgView).offset(12);
            make.trailing.mas_equalTo(-12);
            make.height.mas_greaterThanOrEqualTo(10);
            make.bottom.mas_equalTo(self.bgView.mas_bottom).offset(-12);
        }];
    }
    return _contentLabel;
}

- (UILabel*)dateLabel{
    if (!_dateLabel) {
        _dateLabel = [UILabel new];
        _dateLabel.font = [UIFont systemFontOfSize:11];
        _dateLabel.textColor = UIColorHex(#929292);
        _dateLabel.numberOfLines = 0;
        [self.bgView addSubview:_dateLabel];
        [_dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(3);
            make.leading.mas_equalTo(self.titleLabel);
            make.trailing.mas_equalTo(self.titleLabel);
            make.height.mas_greaterThanOrEqualTo(10);
        }];
    }
    return _dateLabel;
}

- (UIImageView*)avatarIV{
    if (!_avatarIV) {
        _avatarIV = [[UIImageView alloc] init];
        _avatarIV.layer.cornerRadius = 17;
        _avatarIV.layer.masksToBounds= YES;
        [self.bgView addSubview:_avatarIV];
        [_avatarIV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(12);
            make.top.mas_equalTo(12);
            make.height.width.mas_equalTo(34);
            
        }];
    }
    return _avatarIV;
}

@end
